package scoutobahn.xml;

import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
/**
 * An OsmRelation. An OsmRelation is a list of related node, ways etc.
 * @author mark
 *
 */
public class OsmRelation extends OsmItem {

    private final Map<Long, OsmRelationMember> member;
    /**
     * Construct's a new OsmRelation with the given id and the given members.
     * @param newId The id of the relation
     * @param tags The tags of the relation
     * @param newMember Collection of members of this relation
     */
    public OsmRelation(final long newId,
            final Map<String, String> tags,
            final Collection<OsmRelationMember> newMember) {
        super(newId, tags);
        this.member = new HashMap<Long, OsmRelationMember>(newMember.size());
        this.buildFromList(newMember);
    }
    /**
     * Builds the internal map of members from the given list
     * of OsmRelationMember.
     * @param list The list of member
     */
    private void buildFromList(final Iterable<OsmRelationMember> list) {
        for (OsmRelationMember item : list) {
            this.member.put(item.getReferencedItem().getId(), item);
        }
    }
    /**
     * Returns a collection of all members of this relation.
     * @return All member
     */
    public Collection<OsmRelationMember> getMember() {
        return this.member.values();
    }

}
